package learnjava.jvm;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class TestInline {

    int[] elements = randomInts(1_000);
    private static int[] randomInts(int size) {
        Random random = ThreadLocalRandom.current();
        int[] values = new int[size];
        for (int i = 0; i < size; i++) {
            values[i] = random.nextInt();
        }
        return values;
    }

    public static void main(String[] args) {
        TestInline testInline = new TestInline();
        testInline.test1(testInline);
    }
    public void test1(TestInline testInline){
        int[] ele = testInline.elements;
        int y = 0;
        for (int j = 0; j < 200; j++) {
            long start = System.nanoTime();
            for (int i = 0; i < testInline.elements.length; i++) {
                y = testInline.elements[i];
            }
//            for (int i = 0; i < ele.length; i++) {
//                y = ele[i];
//            }
            long end = System.nanoTime();
            System.out.println(""+y+","+(end - start));
        }
    }

}
